package userInterface;

import javax.swing.JPanel;
import java.awt.GridBagLayout;
import javax.swing.JLabel;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import javax.swing.JButton;

import org.apache.mahout.cf.taste.common.TasteException;
import org.apache.mahout.cf.taste.recommender.RecommendedItem;

import controller.Controller;
import domain.Movie;

import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.SQLException;
import java.util.List;

public class RecommendPanel extends JPanel {

	private Controller controller;
	/**
	 * Create the panel.
	 */
	public RecommendPanel(final Controller controller) {
		this.controller = controller;
		setLayout(null);
		
		JPanel panel = new JPanel();
		panel.setBounds(10, 11, 690, 83);
		add(panel);
		panel.setLayout(new GridLayout(1, 0, 0, 0));
		
		JButton btnNewButton_1 = new JButton("Recommend");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				List<RecommendedItem> movieRecommended = null;
				try {
					movieRecommended = controller.getRecommend(1);
				} catch (TasteException e2) {
					// TODO Auto-generated catch block
					e2.printStackTrace();
				}
				Movie movie = null;
				try {
					movie = controller.searchMovieById((int) movieRecommended.get(0).getItemID());
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				RateDialog rDialog = new RateDialog(movie, controller);
				rDialog.setVisible(true);
			}
		});
		panel.add(btnNewButton_1);

	}
}
